package pri.niddles.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pri.niddles.domain.Article;
import pri.niddles.mapper.IArticleMapper;
import pri.niddles.service.IArticleService;


import java.util.List;

@Service
public class ArticleServiceImpl implements IArticleService {
    @Autowired
    private IArticleMapper articleMapper;
    @Override
    //@Cacheable(value = "article" )
    public List<Article> selectAll() {
        List<Article> articles = articleMapper.selectAll();
        for (Article article : articles) {
            System.out.println(article);
        }
        return articles;
    }

    @Override
    public String addArticle(Article article) {
        int i = articleMapper.addArticle(article);
        if (i == 1){
            return "add success";
        }
        return "add failure";
    }

    @Override
    public String delectById(Integer id) {
        int i = articleMapper.delectById(id);
        if (i==1){
            return "success delete";
        }
        return "failure, check out mapper layer logic";
    }

    @Override
    public String updateArticle(Article article) {
        int i = articleMapper.update(article);
        if (i==1){
            return "success update";
        }else {
            return "failure, check out mapper layer logic";
        }
    }


//    @Override
//    public String addArticle(Article article) {
//        System.out.println(article.toString());
//        Date articlePublicTime = article.getArticlePublicTime();
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
//        String format = sdf.format(articlePublicTime);
//        System.out.println(format);
//        articleMapper.addArticle(article);
//
//        return "添加成功";
//    }
}
